<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class user extends MY_Controller {
	private $userId;
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		$this->load->model ( 'friendsreferral_model' );
		$this->load->model ( 'theirwishes_model' );
		$this->load->model ( 'yearbook_model' );
		$this->load->model ( 'photowall_model' );
		$this->load->library ( 'code_fragment' );
		$this->load->model ( 'user_model' );
	}
	/**
	 * 显示 推荐好友 主页 
	 * Enter description here ...
	 */
	function index($userId = '') {
		$userId = empty ( $userId ) ? $this->session->userdata ( "userId" ) : $userId;
		$this->gotoUser ( $userId );
	}
	function getFridensList() {
		//$data=$_POST;
		$array = $this->friendsreferral_model->queryFriendsList ( $_POST );
		echo json_encode ( $array );
	}
	function addFriends() {
		$data = json_encode ( $this->friendsreferral_model->addReferral ( $_POST ) );
		log_message ( "info", $data );
		echo $data;
	}
	function userTjHytj() {
		log_message ( "info", "session user id ==>>" . $this->getUserIdSession () );
		echo $this->getUserIdSession ();
	}
	function userDynamicAdd($type = '', $userId = '') {
		log_message ( "info", $userId . "user id ==" );
		$array = array ();
		$rs = $this->user_model->queryOneUserInfo ( $_POST );
		$_POST ['perserteeName'] = $rs ["nickName"];
		switch ($type) {
			case 'hytj' :
				$array = $this->friendsreferral_model->addReferral ( $_POST );
				break;
			case 'qzf' :
				$array = $this->theirwishes_model->addTheirwishes ( $_POST );
				break;
			case 'yearbook' :
				$array = $this->yearbook_model->addYearbook ( $this->__deleteKey ( 'perserteeName', $_POST ) );
				break;
			case 'photowall' :
				$_POST ["userId"] = $userId;
				$array = $this->photowall_model->addPhotowall ( $_POST );
				break;
			default :
				$this->load->model ( "util/up_down_model" );
				$array = $this->up_down_model->upLoadImage ();
				break;
		}
		echo json_encode ( $array );
	}
	/**
	 * Enter description here ...
	 * @param type
	 * @param _POST
	 */
	private function addUserInfo($type, $data, $userId) {
		$array = array ();
		$rs = $this->user_model->queryOneUserInfo ( $data );
		$_POST ['perserteeName'] = $rs ["nickName"];
		switch ($type) {
			case 'hytj' :
				$array = $this->friendsreferral_model->addReferral ( $data );
				break;
			case 'qzf' :
				$array = $this->theirwishes_model->addTheirwishes ( $data );
				break;
			case 'yearbook' :
				$array = $this->yearbook_model->addYearbook ( $this->__deleteKey ( 'perserteeName', $_POST ) );
				break;
			case 'photowall' :
				$data ["userId"] = $userId;
				$array = $this->photowall_model->addPhotowall ( $data );
				break;
			default :
				$this->load->model ( "util/up_down_model" );
				$array = $this->up_down_model->upLoadImage ();
				break;
		}
		return $array;
	}
	
	/**
	 * 删除指定的 key 返回数组
	 * Enter description here ...
	 * @param  $key 要数组删除的key string
	 * @param  $data  操作数组 Array
	 */
	function __deleteKey($key, $data) {
		if (array_key_exists ( $key, $data )) {
			unset ( $data [$key] );
		}
		return $data;
	}
	
}
?>